package com.kawa.kemanage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kawa.kemanage.entity.UserReports;
import com.kawa.kemanage.mapper.UserReportMapper;
import com.kawa.kemanage.service.UserReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserReportServiceImpl implements UserReportService {
    @Autowired
    private UserReportMapper userReportMapper;



    /**
     * 修改处理状态
     *
     * @param reportId   举报信息的id
     * @param status     处理的状态
     * @param resolution 处理结果
     * @param userId     进行处理的管理员的id
     * @return true/false
     */
    @Override
    public boolean handleReport(Integer reportId, String status, String resolution, Integer userId) {
        return (userReportMapper.updateReportStatus(reportId, status, resolution, userId)) > 0;
    }

    /**
     * 撤销举报
     *
     * @param reportId 举报信息的id
     * @param userId   进行处理的管理员的id
     * @return true/false
     */
    @Override
    public boolean cancelReports(Integer reportId, Integer userId) {
        return (userReportMapper.cancelReport(reportId, userId)) > 0;
    }



    /**
     * 批量删除举报信息（支持单个删除）
     * @param reportIds 举报ID列表
     * @return
     */
    @Override
    public boolean batchDeleteReport(List<Integer> reportIds) {
        return (userReportMapper.batchDeleteReport(reportIds) > 0);
    }

    /**
     * 根据条件查询
     * @param pageNo 页码
     * @param pageSize 页面大小
     * @param reason 举报理由
     * @param status 处理状态
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @Override
    public PageInfo<UserReports> queryReport(
            Integer pageNo,
            Integer pageSize,
            String reason,
            String status,
            Date startDate,
            Date endDate
    ) {
        PageHelper.startPage(pageNo, pageSize);
        List<UserReports> reports = userReportMapper.queryReport(reason, status, startDate, endDate);
        return new PageInfo<>(reports);
    }
}
